<template>
  <div>
    <el-table v-loading="loading" :data="dataSource" :height="autoHeight" border @row-click="handleRowClick" empty-text="还未添加数据模型">
      <el-table-column prop="callCmd" label="调用指令" align="center">
        <template slot="header" slot-scope="scope">
          <div>{{ scope.column.label }}</div>
          <el-input v-model="filterModel[scope.column.property]" :placeholder="scope.column.label + '过滤'" clearable @change="filterChange(scope.column.property)"></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="modelName" label="模型名称" align="center">
        <template slot="header" slot-scope="scope">
          <div>{{ scope.column.label }}</div>
          <el-input v-model="filterModel[scope.column.property]" :placeholder="scope.column.label + '过滤'" clearable @change="filterChange(scope.column.property)"></el-input>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="90px">
        <template slot="header">
          <el-button v-if="!select" type="primary" @click="$emit('rowClick',{})" icon="el-icon-circle-plus-outline" title="新增"></el-button>
        </template>
        <template slot-scope="scope">
          <el-button v-if="select" type="success" icon="el-icon-thumb" circle @click="$emit('rowSelect',scope.row)" title="选择"></el-button>
          <el-button v-else type="danger" icon="el-icon-delete" circle @click="removeData(scope.row, scope.$index)" title="删除"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="lab-table-page">
      <div style="display: inline-flex">
        <el-pagination
            :disabled="loading"
            :current-page="pageInfo.page"
            :page-sizes="[5, 10, 15, 20, 50, 100]"
            :page-size="pageInfo.pageSize"
            layout="total, sizes, jumper"
            :total="pageInfo.total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
        />
        <el-button-group style="padding: 2px 5px">
          <el-button icon="el-icon-refresh" title="刷新" :disabled="loading" @click="loadSource([])" />
        </el-button-group>
      </div>
    </div>
  </div>
</template>

<script>
import IdeaTable from "@/mixins/IdeaTable";

export default {
  name: "ModelList",
  mixins: [IdeaTable],
  props: {
    select: {
      type: Boolean,
      default: false
    }
  },
  computed:{
    autoHeight() {
      return this.select ? '300px' : `calc(100vh - 130px)`
    }
  },
  created() {
    this.queryUrl = 'model/queryPage'
    this.removeUrl = 'model/delete/'
    this.rowKey = 'modelId'
    this.loadSource()
  }
}
</script>

<style scoped>

</style>
